﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.User.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Web.DL.User;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.DL.Project.Entity;

public partial class Theme_DL_EditUser : PowerCreator.LMS.Web.Base.BasePage
{
    //User opUser = new User();
    //Department opDepartment = new Department();
    PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    LogicServer.NetMeetingClass objNetMeetingClass ;
    protected void Page_Load(object sender, EventArgs e)
    {
        //this.Title = config.GetLanagerValueByKey("SysManagerRegistor", PowerCreator.LMS.Language.LanagetItemType.Page);
        if (!IsPostBack)
        {
            InitPage();
            BinderPage();
            //this.btn_AddNew.Attributes.Add("OnClick", "return checkForm()");
            
            if (PowerCreator.LMS.Web.Config.WebConfig.IsUseNetMeeting)
            {
                objNetMeetingClass = new LogicServer.NetMeetingClass();
            }

        }
    }

    protected  void InitPage()
    {

        //lbl_InfoTitle_AddStudent.Text = config.GetLanagerValueByKey("SysManagerRegistor", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Account_loading.Text = config.GetLanagerValueByKey("lbl_AddStudent_Account_loading", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_LoadingName.Text = config.GetLanagerValueByKey("lbl_AddStudent_LoadingName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_PassWord.Text = config.GetLanagerValueByKey("lbl_AddStudent_PassWord", PowerCreator.LMS.Language.LanagetItemType.Page);

        //lbl_dbPassWord.Text = config.GetLanagerValueByKey("lbl_AddStudent_DBPassWord", PowerCreator.LMS.Language.LanagetItemType.Page);

        lbl_BaseInformaition.Text = config.GetLanagerValueByKey("lbl_AddStudent_BaseInformaition", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_AddStudent_Name.Text = config.GetLanagerValueByKey("lbl_AddStudent_Name", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Number.Text = config.GetLanagerValueByKey("lbl_AddStudent_Number", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Sex.Text = config.GetLanagerValueByKey("lbl_AddStudent_Sex", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_IdNumber.Text = config.GetLanagerValueByKey("lbl_AddStudent_IdNumber", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Born.Text = config.GetLanagerValueByKey("lbl_AddStudent_Born", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Mail.Text = config.GetLanagerValueByKey("lbl_AddStudent_Mail", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_Nation.Text = config.GetLanagerValueByKey("lbl_AddStudent_Nation", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Phone.Text = config.GetLanagerValueByKey("lbl_AddStudent_Phone", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Native.Text = config.GetLanagerValueByKey("lbl_AddStudent_Native", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Post.Text = config.GetLanagerValueByKey("lbl_AddStudent_Post", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_MobileTelephone.Text = config.GetLanagerValueByKey("lbl_AddStudent_MobileTelephone", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Native.Text = config.GetLanagerValueByKey("lbl_AddStudent_Native", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Address.Text = config.GetLanagerValueByKey("lbl_AddStudent_Address", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Remark.Text = config.GetLanagerValueByKey("lbl_AddStudent_Remark", PowerCreator.LMS.Language.LanagetItemType.Page);
        radbtn_Male.Text = config.GetLanagerValueByKey("EditUser_desc27", PowerCreator.LMS.Language.LanagetItemType.Page);
        radbtn_Female.Text = config.GetLanagerValueByKey("EditUser_desc28", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_addstudent_selClass.Text = config.GetLanagerValueByKey("lbl_addstudent_selClass", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_Birth_css.Text = "* (" + config.GetLanagerValueByKey("theme_Register_Msg1", PowerCreator.LMS.Language.LanagetItemType.Page) + "：1980-01-01)";

        btn_AddNew.Text = config.GetLanagerValueByKey("btn_EditNew", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Reset.Text = config.GetLanagerValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);

       
    }

    private void BinderPage()
    {
        try
        {
            txt_UserName.Text = GetLoginEntity.UserName;
            int uid = GetLoginEntity.UserID;
            TOLearner obj = new TOLearner();
            //if (GetLoginEntity.AccountType == PowerCreator.LMS.Web.User.LoginUserType.Student)
            //{
            VOTOLearner vo = new VOTOLearner();
            vo = obj.Load(uid);

                txt_RealName.Text = vo.Name;
                txt_StudentCode.Text = vo.TeacherId.ToString();
                if (!vo.Sex )
                    radbtn_Male.Checked = true;
                else
                    radbtn_Female.Checked = true;
                txt_Idcard.Text = "";
                txt_Birth.Text = vo.Birthday.ToShortDateString();
                txt_Email.Text = vo.Email;
                txt_Tel.Text = vo.Mobile;
                txt_MobileTelephone.Text = vo.Mobile;
                //txt_Nation.Text = vo.StudentNation;
                //txt_Post.Text = vo.StudentPost;
                //txt_Address.Text = vo.;
                //txt_Homeplace.Text = vo.StudentHomeplace;
                //txt_Description.Text = vo.;

            //}
            //else if (GetLoginEntity.AccountType == PowerCreator.LMS.Web.User.LoginUserType.Teacher)
            //{
            //    VOTTeacher vo = new VOTTeacher();
            //    vo = objUser.LoadTteacherByUserID(uid);

            //    txt_RealName.Text = vo.TeacherName;
            //    txt_StudentCode.Text = vo.TeacherCode;
            //    if (vo.TeacherSex == 0)
            //        radbtn_Male.Checked = true;
            //    else
            //        radbtn_Female.Checked = true;
            //    txt_Idcard.Text = vo.TeacherIdentityCard;
            //    txt_Birth.Text = vo.TeacherBirthday.ToShortDateString();
            //    txt_Email.Text = vo.TeacherEmail;
            //    txt_Tel.Text = vo.TeacherTelephone;
            //    txt_MobileTelephone.Text = vo.TeacherMobileTelephone;
            //    //txt_Nation.Text = "无";
            //    txt_Post.Text = vo.TeacherPost;
            //    txt_Address.Text = vo.TeacherAddress;
            //    txt_Homeplace.Text = vo.TeacherHomeplace;
            //    txt_Description.Text = vo.TeacherDescription;

            //}
            ////如果是超级管理员帐户或者内置帐户不允许修改个人资料
            //else if (GetLoginEntity.AccountType == PowerCreator.LMS.Web.User.LoginUserType.SuperAdministartor || GetLoginEntity.AccountType == PowerCreator.LMS.Web.User.LoginUserType.InnerUser)
            //{
            //    txt_RealName.ReadOnly = true;
            //    txt_StudentCode.ReadOnly = true;
            //    radbtn_Female.Enabled = false;
            //    radbtn_Male.Enabled = false;
            //    txt_Idcard.ReadOnly = true;
            //    txt_Birth.ReadOnly = true;
            //    txt_Email.ReadOnly = true;
            //    txt_Tel.ReadOnly = true;
            //    txt_MobileTelephone.ReadOnly = true;
            //    //txt_Nation.ReadOnly = true;
            //    txt_Post.ReadOnly = true;
            //    txt_Address.ReadOnly = true;
            //    txt_Homeplace.ReadOnly = true;
            //    txt_Description.ReadOnly = true;
            //    btn_AddNew.Enabled = false;
            //}
        }
        catch (Exception ex)
        {
            return;
        }
    }
    /// <summary>
    /// 检查页面数据
    /// </summary>
    /// <returns></returns>
    private bool CheckPageData()
    {
        //if (!(txt_UserPwd.Text.ToString() == txt_DBUserPwd.Text.ToString()))
        //{
        //    lab_dbPwd.Text = config.GetLanagerValueByKey("theme_Register_Msg5", PowerCreator.LMS.Language.LanagetItemType.Page) ;
        //    return false;
        //} 

        //string search = string.Format("UserName = '{0}'", txt_UserName.Text);
        //if (opUser.Count(search) != 0)
        //{
        //    lbl_AddStudent_msg_username.Text = config.GetLanagerValueByKey("theme_Register_Msg2", PowerCreator.LMS.Language.LanagetItemType.Page);
        //    return false;
        //}

        if (!string.IsNullOrEmpty(txt_Birth.Text))
        {
            if (!TimeUtils.IsDateTime(txt_Birth.Text.Trim()))
            {
                lab_Birth_css.Text = config.GetLanagerValueByKey("theme_Register_Msg3", PowerCreator.LMS.Language.LanagetItemType.Page);
                return false;
            }
        }  
        return true;
    }

    //private void BinderDepartment()
    //{
    //    string search = "DepartmentType=1";
    //    DataTable dt = opDepartment.Query(search);
    //    ArrayList list = opDepartment.GetDepartmentTree(dt);
    //    ddl_Department.DataSource = list;
    //    ddl_Department.DataTextField = "Text";
    //    ddl_Department.DataValueField = "Value";
    //    ddl_Department.DataBind();
    //}
 

    protected void btnAdd_Click(object sender, EventArgs e)
    {

        if (!CheckPageData()) return;
        int uid = GetLoginEntity.UserID;
        TOLearner obj = new TOLearner();
        ////PowerCreator.LMS.Web.CreatedByInfo cinfo = GetCreatedByInfo();
        //if (GetLoginEntity.AccountType == PowerCreator.LMS.Web.User.LoginUserType.Student)
        //{
        VOTOLearner vo = new VOTOLearner();
        vo = obj.Load(uid);


            vo.Name=txt_RealName.Text;
            vo.TeacherId = int.Parse(txt_StudentCode.Text);
            if (radbtn_Male.Checked == true)
                vo.Sex= false;
            else
                vo.Sex = true;
            //vo.StudentIdentityCard = txt_Idcard.Text;
            if (!string.IsNullOrEmpty(txt_Birth.Text))
                vo.Birthday = DateTime.Parse(txt_Birth.Text.Trim());
            vo.Email = txt_Email.Text;
            vo.Mobile = txt_Tel.Text;
            vo.Mobile = txt_MobileTelephone.Text;
            //vo.StudentNation = txt_Nation.Text;
            //vo.StudentPost = txt_Post.Text;
            //vo.StudentAddress=txt_Address.Text ;
            //vo.StudentHomeplace=txt_Homeplace.Text  ;
            //vo.StudentDescription=txt_Description.Text ;
            
            if (obj.Update(vo))
            {
                string url = "StudyCenter.aspx";
                Script.RedirectURL(url);
            }

        //}
        //else if (GetLoginEntity.AccountType == PowerCreator.LMS.Web.User.LoginUserType.Teacher)
        //{
        //    VOTTeacher vo = new VOTTeacher();
        //    vo = objUser.LoadTteacherByUserID(uid);




        //    vo.TeacherName=txt_RealName.Text ;
        //    vo.TeacherCode= txt_StudentCode.Text;

        //    if (radbtn_Male.Checked == true)
        //        vo.TeacherSex = 0;
        //    else
        //        vo.TeacherSex = 1;

        //    vo.TeacherIdentityCard=txt_Idcard.Text ;
        //    if (!string.IsNullOrEmpty(txt_Birth.Text))
        //        vo.TeacherBirthday = DateTime.Parse(txt_Birth.Text.Trim());

        //    vo.TeacherEmail=txt_Email.Text ;
        //    vo.TeacherTelephone=txt_Tel.Text ;
        //    vo.TeacherMobileTelephone=txt_MobileTelephone.Text;

        //    vo.TeacherPost=txt_Post.Text ;
        //     vo.TeacherAddress=txt_Address.Text;
        //    vo.TeacherHomeplace=txt_Homeplace.Text ;
        //    vo.TeacherDescription=txt_Description.Text ;


        //    if (objUser.UpdateTeacher(vo))
        //    {
        //        string url = "StudyCenter.aspx";
        //        Script.RedirectURL(url);
        //    }
        //}



    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "Default.aspx";
        Script.RedirectURL(url);
    }

}
